﻿<div class="page-content-wrap">
    <div id="table-list" class="layui-form" style="height: 400px;">
        <input type="hidden" id="index" />
        <table id="tab"></table>
    </div>
</div>
@section script{
    <script>
        $("#tab").datagrid({
            idField: 'parentid',
            //singleSelect: false,
            //rownumbers: true,
            //pagePosition: 'bottom',
            //pagination: true,//分页
            //pageSize: 10,//每页显示条数
            //pageList: [10, 15, 20, 30, 50, 100], //调整每页显示条数
            fit: true,//宽高跟随父面板
            fitColumns: true,//水平滚动条
            nowrap: false,//折行显示
            columns: [[
                { field: 'check', checkbox: true, width: 100, align: 'center' },
                { field: 'id', title: '管理员编号', width: 180, align: 'center' },
                { field: 'adminName', title: '管理员名称', width: 180, align: 'center' },
                {
                    field: 'edit', title: '操作', width: 150, align: 'center',
                    formatter: function (value, row, index) {
                        return '<button class="layui-btn layui-btn-mini layui-btn-normal add_btn" data-id="" data-url="/Home/EditAdminInfo"><i class="layui-icon">&#xe654;</i></button>' +
                            '<button class="layui-btn layui-btn-mini layui-btn-normal edit_btn" data-id="' + row.id + '" data-url="/Home/EditAdminInfo"><i class="layui-icon">&#xe642;</i></button>' +
                        '<button class="layui-btn layui-btn-mini layui-btn-danger del_btn" data-id="' + row.id + '" data-url="/Home/DeleteAdmin"><i class="layui-icon">&#xe640;</i></button>';
                    }
                }
            ]],
            url: '/Home/AdminInfotable',
        })
        layui.use(['jquery', 'layer', 'dialog', 'checkbox'], function () {
            var $ = layui.jquery;
        });
        $('#table-list').on('click', '.edit_btn', function () {
            var That = $(this);
            var id = That.attr('data-id');
            var url = That.attr('data-url');
            //将iframeObj传递给父级窗口
            layer.open({
                type: 2,
                title:['修改管理员信息'],
                area: ['500px', '400px'],
                content: url + "?id=" + id, //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                cancel: function () {
                    location.reload();
                }
            });
            return false;
        })
        $('#table-list').on('click', '.add_btn', function () {
            var That = $(this);
            var id = That.attr('data-id');
            var url = That.attr('data-url');
            //将iframeObj传递给父级窗口
            layer.open({
                type: 2,
                title:['新增管理员信息'],
                area: ['500px', '400px'],
                content: url + "?id=" + id, //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                cancel: function () {
                    location.reload();
                }
            });
            return false;
        })
        //列表删除
	    $('#table-list').on('click', '.del_btn', function() {
		    var url=$(this).attr('data-url');
		    var no = $(this).attr('data-id');
		     layer.confirm('您确定要删除选中项?', function (index) {
		            //do something
                     $.ajax({
                         type: "post",
                         url: "/Home/DeleteAdminInfo",
                         data: {no:no},
                           // dataType: 'Json',
                           // async:true,
                        success: function (result) {
                            parent.layer.msg(result);
                            location.reload();
                        }
                    });
		            layer.close(index);
		        });
		return false;
	})
    </script>
}